<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8">
    <title>sowRecord</title>
    <script type="text/javascript" src="../../plugs/jquery-3.1.1.min.js"></script>
    <script src="../../assets/bootstrap/js/bootstrap.min.js"></script>
    <!-- boostrap table  -->
   	
	<!-- bootstrap -->
	<link rel="stylesheet" href="../../plugs/bootstrap/css/bootstrap.min.css">
	<script type="text/javascript" src="../../plugs/bootstrap/js/bootstrap.min.js"></script>
	<!-- 分页插件 -->
	<link rel="stylesheet" href="../../plugs/bootstrap-table/bootstrap-table.min.css">
	<script type="text/javascript" src="../../plugs/bootstrap-table/bootstrap-table.min.js"></script>
	<script type="text/javascript" src="../../plugs/bootstrap-table/bootstrap-table-locale-all.min.js"></script>
	<!-- 行内编辑 -->
	<script type="text/javascript" src="../../plugs/editable/bootstrap-editable.js"></script>
	<script type="text/javascript" src="../../plugs/editable/bootstrap-table-editable.js"></script>
    <link rel="stylesheet" href="../../business/Form/css/Form.css">
	<link rel="stylesheet" href="../../css/layer/mobile/need/layer.css">
	<script type="text/javascript" src="../../css/layer/layer.js"></script>
</head>
<body>
<!--计划列表-->
<div class="container" style="margin-top:20px;width: 1200px">
			<div class="row">
				
				<div id="toolbar">
					<input type="button" id="delete" value="删除"/>
					<input type="button" id="search" value="搜索"/>
					<input type="text" id="searchKey"/>				
				</div>
				<div class="col-xs-12">
					<table class="table table-striped table-bordered table-hover" ></table>
				</div>
			</div>
</div>
<script src="../js/buttonStyleCover.js"></script>
<script>
$(document).ready(function() 
{
	init();
	function init()
	{
		/*将用户信息传回后台*/
		var businessId = $(window.parent.parent.frames["topFrame"].document).find('#businessId').text();
		//alert(businessId);
    	 //---先销毁表格 ---
        $('table').bootstrapTable('destroy');  
        //---初始化表格,动态从服务器加载数据--- 
       // alert("hello");
		 $('table').bootstrapTable
		 ({
			//发送数据请求
	    	url: '../getMCopackRecords.do',
			method: 'post',
			//data: {"business":businessId},
			contentType: "application/x-www-form-urlencoded",
			toolbar: '#toolbar',//自定义工具栏
			cache: false,
			height: 600,
			striped: true,
			//search: true,
			//showExport: true,
			//showColumns: true,
			exportTypes: ['csv','txt','xml'],
			clickToSelect: true,
			//【查询设置】
			/* queryParamsType的默认值为 'limit' ,在默认情况下 传给服务端的参数为：offset,limit,sort
                             设置为 ''  在这种情况下传给服务器的参数为：pageSize,pageNumber */
			queryParamsType:'', 
           	queryParams: function queryParams(params) {
           	 //alert(businessId);
             var param = {  
                 pageNumber: params.pageNumber,    
                 pageSize: params.pageSize,
                 business: businessId,
                 searchKey: $('#searchKey').val()
             }; 
             /*
             for(var key in searchArgs){
           	  param[key]=searchArgs[key]
             }  
             */
             return param;                   
           }, 
			//【其它设置】
           locale:'zh-CN',//中文支持
           pagination: true,//是否开启分页（*）
           pageNumber:1,//初始化加载第一页，默认第一页
           pageSize: 10,//每页的记录行数（*）
           pageList: [10,15,20],//可供选择的每页的行数（*）
           sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
           showRefresh:true,//刷新按钮
           //【设置列属性】
			columns:
			 [
				 {field: 'check',checkbox: true},
				 {field: 'id',title: 'id'}, 	
				 {field: 'checkinsegBtcode',title: '入库溯源码'},
				 {field: 'copacktime',title: '包装时间'}, 
				 {field: 'ordernum',title: '订单号'},
				 {field: 'copacklocation',title: '包装地点',editable: true},
				 {field: 'productBtcode',title: '产品溯源码',editable: true},
				 {field: 'copacker',title: '包装员',editable: true},
				 {field: 'producedate',title: '生产日期'},
				 {field: 'producelocation',title: '生产地'},
				 {field: 'specifications',title: '规格'},
				 {field: 'netContent',title: '净含量'},
				 {field: 'storagecondition',title: '贮藏条件'},
				 {field: 'comment',title: '备注',editable: true},
				 //start
				 //页面元素添加
				 {field: 'action',title: "发布物流任务",
					 formatter: function(value,row,index){
						 	
							var productBtcode = String(row.productBtcode)+"";

						 	var element= 
								"<a class='edit' data-id='"+row.id +"' onclick=\"publishTask('"+row.productBtcode+"','"+row.ordernum+"')\">发布任务</a> ";
							return element;
					 }
				 }
				 //end
			 
			 /* ,	 
			 {field: 'action',title: '操作',
				 formatter:function(value,row,index){
					    var element = 
					    "<a target='_blank' href='http://localhost:8081/CropBacktracking/lifeline.html' class='view' data-id='"+row.id +"'>预览</a> "+ 
					    "<a class='edit' data-id='"+row.id +"'>编辑</a> ";
					    return element;  
					} 
			 } */
			 /*
			 {field: 'seedsource',title: '地点', align: 'center',
				formatter:function(value,row,index){
				    var element = 
				    "<a class='edit' data-id='"+row.id +"'>编辑</a> "+ 
				    "<a class='delet' data-id='"+row.id +"'>删除</a> ";
				    return element;  
				} 
			  }
			  */
			],
           
			//行内编辑保存事件
			onEditableSave: function (field, row, oldValue, $el)
			{
					update(row);
			}	
           
           
       });	 

	};
	//查询
	$('#search').click(function()
	{
		init();
	});

	  //删除数据
	 $('#delete').click(function(){
		 var rows = $('table').bootstrapTable('getSelections');
		 var rowsNum = rows.length;
		 if(rowsNum == 0)
		 {
			 alert("未选择数据")
		 }
		 else
		 {
			 //alert(rows[0].check);
			 //删除第一个check对象，后台不需要，必须处理
			 for(var i =0 ;i< rowsNum ;i++)
				delete rows[i]['check'];
			 $.ajax({
				  type: "post",
				  url: "../delCopackRecordInfo.do",
				  data:{data:JSON.stringify(rows)},
				  //data:	rows,
				  success: function (data, status) {
					  if (status == "success") {
						  layer.msg("删除成功",{icon: 1})
	                        //成功之后页面数据删除
	                        //$('table').bootstrapTable('remove');
	                    }
	                },
	                error: function () {
						layer.msg("删除失败",{icon: 5})
	                }
	            });
		  }
	  });
	 //修改数据
	 function update(row)
	  {
		  //向服务器提交数据
		  $.ajax({
			  type: "post",
			  url: "../updateCopackRecordInfo.do",
			  //data:{data:JSON.stringify(rows)},
			  data:	row,
			  success: function (data, status) {
				  if (status == "success") {
					  layer.msg("修改成功",{icon: 1})
                   }
               },
               error: function () {
				   layer.msg("修改失败",{icon: 5})
               }
           });      
		  //end
	  };
	  
	  
	
	});	




//start
//2017-07-24
function publishTask(productBtcode,ordernum)
{
	/*
	BUG
	*/
	//alert(productBtcode);
	//alert(ordernum);

	  //将数据返回服务器，发送邮件给指定的人员
	  $.ajax({
		  type:"post",
		  url:"../sendDeliverTaskEmail.do",
		  data:{
			  "productBtcode":productBtcode,
			  "ordernum":ordernum
		  },
		  success: function(data,status){
			  if(data=="true")
			  {
				  layer.msg("任务发布成功",{icon: 1})
			  }
			  else
			  {
				  layer.msg("任务发送失败",{icon: 5})
		      }
		  },
		  error: function(status)
		  {
			  layer.msg("系统错误",{icon: 5})
		  }
	  });		  
}
//end

</script>
</body>
</html>